<template>
	<view>
		<view class="u-page">
			<view class="u-demo-block">
				<view class="u-demo-block__content">
					<u-notice-bar :text="noticeBar"></u-notice-bar>					
				</view>
			</view>
		</view>
		<view class="u-page">
			<view class="u-demo-block">
				<u-swiper :list="images" keyName="url"></u-swiper>
			</view>
		</view>
		<u-grid :border="false" col="4">
			<u-grid-item v-for="(listItem,listIndex) in list" :key="listIndex">
				<u-icon :customStyle="{paddingTop:30+'rpx'}" :name="listItem.name" :size="22"></u-icon>
				<text class="grid-text">{{listItem.title}}</text>
			</u-grid-item>
		</u-grid>
		<!-- <u-toast ref="uToast" /> -->
		<u-divider text="最新公告" textPosition="left"></u-divider>
		<u-cell-group>
			<!-- <u-cell size="large" title="单元格" value="内容" isLink></u-cell> -->
			<view v-for="notice in noticeList">
				<u-cell size="large" :title="notice.noticeTitle" :value="omit(notice.noticeContent)" :label="notice.noticeTime" isLink :url="noticeUrl+notice.noticeId"></u-cell>
			</view>
		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noticeBar: 'uView UI众多组件覆盖开发过程的各个需求，组件功能丰富，多端兼容。让您快速集成，开箱即用',
				imageList: [],
				images:[],
				list: [{
						name: 'zhifubao',
						title: '物业缴费'
					},
					{
						name: 'lock-open',
						title: '开门'
					},
					{
						name: 'setting',
						title: '申报维修'
					},
					{
						name: 'list-dot',
						title: '便民助手'
					}
				],
				noticeList:[],
				noticeUrl: "./noticeDetail?noticeId="
			}
		},
		onLoad() {
			let token = uni.getStorageSync("token");
			if (!token) {
				uni.redirectTo({
					url: "../loginByAccount"
				})
			}
			let that = this;
			uni.request({
				url:"/notice/list",
				success(res) {
					// console.log(res)
					that.noticeList = res.data.data
				}
			});
			uni.request({
				url:"/admin/image/list",
				success(res) {
					// console.log(res)
					that.imageList = res.data.data;
					if(that.imageList != null){
						that.imageList.forEach(k => {
							// console.log(k)
							let picture = {}
							picture.title = k.imagePath;
							picture.url = "https://7529yh2880.zicp.fun/admin/image/loadimage/?fileName="+k.imagePath
							that.images.push(picture)
						})
						console.log(that.images)
					}
				}
			})
		},
		methods: {
			omit(content){
				let newContent = content;
				if(content.length > 7){
					newContent = content.substring(0,7)+"..."
				}
				return newContent;
			}
		}
	}
</script>

<style lang="scss">


</style>